package com.example.demo.app;

import com.example.demo.domain.app.param.OrderSubmitParam;
import com.example.demo.domain.app.vo.OrderAmountSummaryVO;
import com.example.demo.domain.app.vo.OrderListDataVO;
import com.example.demo.domain.app.vo.OrderStatisticsVO;
import com.example.demo.domain.base.BaseResult;
import com.example.demo.domain.base.PageResult;
import com.example.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * OrderController
 *
 * @author haochen78
 * @date 2025/11/17 00:18
 **/
@RestController
@RequestMapping("/app/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     */
    @PostMapping("/create")
    public BaseResult<OrderAmountSummaryVO> create(@RequestBody OrderSubmitParam param) {
        Boolean calculate = param.getCalculate();
        if (Boolean.TRUE.equals(calculate)) {
            return BaseResult.success(orderService.preview(param));
        }
        return BaseResult.success(orderService.create(param));
    }

    /**
     * 订单统计
     */
    @GetMapping("/statistics")
    public BaseResult<OrderStatisticsVO> statistics() {
        return BaseResult.success(new OrderStatisticsVO());
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public BaseResult<PageResult<OrderListDataVO>> list() {
        return BaseResult.success();
    }

}
